<template>
  <div class="w-container">
    <input type="text" placeholder="回复" class="text" v-model="value" />
    <button @click="submmit">发布</button>
  </div>
</template>
<script>
import axios from "@/util/axios";

export default {
  name: "WriteReply",
  data() {
    return {
      value: "",
    };
  },
  props: {
    message: {
      type: Object,
      default() {
        return {
          // answer_id: '',
          // replied_id: '',
          // pid: ''
        }
      }
    }
  },
  methods: {
    submmit() {
      if (this.value === "") return;
      else {
        axios
          .post("comment/commentAnswer", {
            data: {
              content: this.value,
              reply_id: localStorage.getItem("userId"),
              ...this.message
            },
          })
          .then((res) => {
            console.log(res);
            if(res.code === '1') {
              //重新获取所有评论
              this.$Message.success('回答成功')
              //隐藏回复框
              this.$parent.hideReply()
              this.$parent.reGetComment()
              this.value = ''
            }
          });
      }
    },
  },
  mounted() {
    console.log(this.$parent.$parent.answerMessage);
  },
};
</script>

<style scoped lang='scss'>
.w-container {
  height: 3.8rem;
  margin-bottom: 1rem;
  width: 100%;
  input {
    width: 84%;
    height: 100%;
    outline: 1px solid #8590a6;
    padding: 0.6rem 1.2rem;
    margin-right: 1.2rem;
  }
  button {
    width: 10%;
    height: 100%;
    background-color: #0084ff;
    color: #fff;
    border-radius: 0.3rem;
  }
}
</style>